package com.web.music.interfaces;

import java.util.List;

import com.web.music.model.PersistentEntity;
import com.web.music.model.Track;

/**
 * Interface for general operations with persistent objects.
 * @see PersistentEntityRegistry for enumeration of persistent entities.
 */
public interface PersistenceHelper {
	
	/**
	 * Saves object in a database.
	 * @param object to be saved
	 */
	public void save(PersistentEntity object);
	
	/**
	 * Saves all list elements in a database.
	 * @param objects - list of objects to be saved
	 */
	public void saveAll(List<? extends PersistentEntity> objects);
	
	/**
	 * Retrieves instance of object of certain type from database by id.
	 * @param clazz - class of persistent object
	 * @param id - id of object to be retrieved
	 * @return object instance from database
	 */
	public PersistentEntity getById(Class<? extends PersistentEntity> clazz, Long id);
	
	/**
	 * Returns all objects of certain type from database.
	 * @param clazz - class of persistent object
	 * @return list of objects from database
	 */
	public List<PersistentEntity> findAll(Class<? extends PersistentEntity> clazz);
	
    
	public List<Track> findTracksByName(String s);
    public List<Track> findTracksByArtistId(Long id);
    public List<Track> findTracksByPersonId(Long id);
    
	/**
	 * Deletes object from database.
	 * @param object to be deleted
	 */

	
	public void delete(PersistentEntity object);
	
	/**
	 * Deletes all objects from database.
	 */
	public void cleanupDB();
	
	/**
	 * Determine if 'id' field of provided Class is annotated with @GeneratedValue
	 * @param clazz to be checked
	 * @return
	 */
	public boolean isIdGenereated(Class<? extends PersistentEntity> clazz);
}
